using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.CodeRush.StructuralParser;
using DevExpress.CodeRush.Core;

namespace DX_SourceOutliner
{
    public class ToolTipProcessor : INodeProcessor
    {
        private LanguageElement _element;

        private ISourceTreeNode _sourceNode;

        public TreeNode Process(TreeNode node)
        {

            _sourceNode = node.Tag as ISourceTreeNode;

            _element = _sourceNode.Element as LanguageElement;

            if (_element == null)
                return node;

            switch (_element.ElementType)
            {
                case LanguageElementType.Namespace:
                    {
                        Namespace namespaceElement = _element as Namespace;

                        if (namespaceElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();

                    }
                    break;

                case LanguageElementType.Method:
                    {
                        Method methodElement = _element as Method;

                        if (methodElement != null)
                            node.ToolTipText = GetToolTipTextWithReturnType();
                    }
                    break;

                case LanguageElementType.Class:
                    {
                        Class classElement = _element as Class;

                        if (classElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                case LanguageElementType.Variable:
                case LanguageElementType.InitializedVariable:
                    {
                        Variable variableElement = _element as Variable;

                        if (variableElement != null)
                            node.ToolTipText = GetToolTipTextWithReturnType();
                    }
                    break;

                case LanguageElementType.Struct:
                    {
                        Struct structElement = _element as Struct;

                        if (structElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                case LanguageElementType.Property:
                    {
                        Property propertyElement = _element as Property;

                        if (propertyElement != null)
                            node.ToolTipText = GetToolTipTextWithReturnType();
                    }
                    break;

                case LanguageElementType.Delegate:
                    {
                        DelegateDefinition delegateElement = _element as DelegateDefinition;

                        if (delegateElement != null)
                            node.ToolTipText = GetToolTipTextWithReturnType();
                    }
                    break;

                case LanguageElementType.Interface:
                    {
                        Interface interfaceElement = _element as Interface;

                        if (interfaceElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                case LanguageElementType.Enum:
                    {
                        Enumeration enumerationElement = _element as Enumeration;

                        if (enumerationElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                case LanguageElementType.EnumElement:
                    {
                        EnumElement enumerationElementElement = _element as EnumElement;

                        if (enumerationElementElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                case LanguageElementType.Event:
                    {
                        Event eventElement = _element as Event;

                        if (eventElement != null)
                            node.ToolTipText = GetToolTipTextWithoutReturnType();
                    }
                    break;

                default:
                    break;
            }

            return node;

        }

        private string GetToolTipTextWithoutReturnType()
        {
            return string.Format("{0} {1}", _sourceNode.MemberVisibilityText, _element.ElementType.ToString());
        }

        private string GetToolTipTextWithReturnType()
        {
            return string.Format("{0} {1} : {2}", _sourceNode.MemberVisibilityText, _element.ElementType.ToString(), _sourceNode.TypeDeclarationText);
        }

    }
}

